package com.example.common.service.impl;

import com.example.common.mapper.ICompInfoMapper;
import com.example.common.mapper.IDataLogMapper;
import com.example.common.pojo.CompInfo;
import com.example.common.service.ICompInfoService;
import com.example.right.service.IRightService;
import com.example.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ICompInfoServiceImpl implements ICompInfoService {

    private final ICompInfoMapper iCompInfoMapper;
    private final IRightService iRightService;
    private final IDataLogMapper iDataLogMapper;
    @Autowired
    public ICompInfoServiceImpl(ICompInfoMapper iCompInfoMapper,IDataLogMapper iDataLogMapper,IRightService iRightService){
        this.iCompInfoMapper=iCompInfoMapper;
        this.iDataLogMapper=iDataLogMapper;
        this.iRightService=iRightService;
    }
    @Override
    public CompInfo getCompInfoByName(String name) {
        return this.iCompInfoMapper.getCompInfoByName(name);
    }

    /**
     * 删除企业信息
     *
     * @param name 企业名字
     * @return 删除是否成功
     */
    @Override
    public int deleteCompInfo(Integer id,String name) {
        if(!this.iRightService.checkPermission(id,Constants.DELETE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.DELETE,id,name);
        return this.iCompInfoMapper.deleteCompInfo(name);
//        return this.iDataLogMapper.insertDataLog(Constants.DELETE,id,name);
    }

    /**
     * @param compInfo
     * @return
     */
    @Override
    public int insertCompInfo(Integer id ,CompInfo compInfo) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT))
        {
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,compInfo.toString());
        return this.iCompInfoMapper.insertCompInfo(compInfo.getComOrderamount(),compInfo.getComShedTotalamount(),
                compInfo.getComWellPrice(),
                compInfo.getComWellTotalamount(),
                compInfo.getComDoorPrice(),
                compInfo.getComDoorTotalamount(),compInfo.getComFencePrice(),
                compInfo.getComFenceTotalamount(),
                compInfo.getComPhonePrice(),
                compInfo.getComPhoneTotalamount(),
                compInfo.getComTvPrice(),
                compInfo.getComTvTotalamount(),
                compInfo.getComName(),
                compInfo.getComAdress(),
                compInfo.getComProject(),
                compInfo.getComNotetaker(),
                compInfo.getComSurveyor(),
                compInfo.getComShedNum(),
                compInfo.getComShedPrice(),
                compInfo.getComWellNum(),compInfo.getComDoorNum(),
                compInfo.getComFenceNum(),
                compInfo.getComPhoneNum(),
                compInfo.getComTvNum(),
                compInfo.getComFillinPerson(),
                compInfo.getComFillinDate(),
                compInfo.getComOrder(),compInfo.getComRelocatedPerson(),
                compInfo.getComBeRelocatedPerson(),
                compInfo.getComTableNo(),compInfo.getComMeasureDate());
//        return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,compInfo.toString());

    }

    @Override
    public int updateCompInfo(Integer id,CompInfo compInfo) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE))
        {
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,compInfo.toString());
        return this.iCompInfoMapper.updateCompinfo(compInfo.getComOrderamount(),compInfo.getComShedTotalamount(),
                compInfo.getComWellPrice(),
                compInfo.getComWellTotalamount(),
                compInfo.getComDoorPrice(),
                compInfo.getComDoorTotalamount(),compInfo.getComFencePrice(),
                compInfo.getComFenceTotalamount(),
                compInfo.getComPhonePrice(),
                compInfo.getComPhoneTotalamount(),
                compInfo.getComTvPrice(),
                compInfo.getComTvTotalamount(),
                compInfo.getComName(),
                compInfo.getComAdress(),
                compInfo.getComProject(),
                compInfo.getComNotetaker(),
                compInfo.getComSurveyor(),
                compInfo.getComShedNum(),
                compInfo.getComShedPrice(),
                compInfo.getComWellNum(),compInfo.getComDoorNum(),
                compInfo.getComFenceNum(),
                compInfo.getComPhoneNum(),
                compInfo.getComTvNum(),
                compInfo.getComFillinPerson(),
                compInfo.getComFillinDate(),
                compInfo.getComOrder(),compInfo.getComRelocatedPerson(),
                compInfo.getComBeRelocatedPerson(),
                compInfo.getComTableNo(),compInfo.getComMeasureDate());
//        return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,compInfo.toString());
    }
}
